package com.thb.pay.feigin.abs;

import com.netflix.discovery.DiscoveryManager;
import com.thb.pay.core.handler.RRExceptionHandler;
import com.thb.pay.feigin.config.FeignMappingDefaultConfig;
import com.thb.pay.feigin.filter.FeignErrorDecoder;
import feign.codec.ErrorDecoder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.util.TimeZone;

/**
 * <p>描述：微服务基本配置</p>
 *
 * @date 2018/03/06
 */
@Slf4j
@EnableEurekaClient
@EnableHystrix
@Import({RRExceptionHandler.class, FeignMappingDefaultConfig.class})
public abstract class AbstractApplication {
    /**
     * 时区统一处理
     */
    @PostConstruct
    void started() {
        log.info("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<init.timeZone>>>>>>>>>>>>>UTC>>>>>>>>>>>>>>>>>>>>>>>>>>>");
        TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
    }

    /**
     * 错误转码业务异常
     *
     * @return
     */
    @Bean
    public ErrorDecoder errorDecoder() {
        return new FeignErrorDecoder();
    }

    @PreDestroy
    public void eurekaOffline() {
        DiscoveryManager.getInstance().shutdownComponent();
    }

}
